<?php

class Model_Orm_Genre extends \Orm\Model
{
    protected static $_primary_key = array('id');
    protected static $_properties = array(
            'id',
            'genre_lv',
            'genre_en'
    );
    protected static $_table_name = 'genres';
    
    protected static $_has_many = array(
	'movie' => array(
	    'key_from' => 'id',
	    'model_to' => 'Model_Orm_Movie',
	    'key_to' => 'id',
	    'cascade_save' => true,
	    'cascade_delete' => true)
    );
    
    public static function load_genres($lang = "lv")
    {
	return \DB::select('id', 'genre_'.$lang)
		    ->from('genres')
		    ->execute()
		    ->as_array('id', 'genre_'.$lang);
    }
    
    public static function validate($factory) {
        $val = Validation::forge($factory);
        
        $val->add_field('Genre_Lv', 'Žanrs latviski', 'required|max_length[50]|min_length[2]');
        $val->add_field('Genre_En', 'Žanrs angliski', 'required|max_length[50]|min_length[2]');
        
        return $val;
    }
}
